﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mrkz.ImageManipulation.SpatialFiltering
{
    /// <summary>
    /// this filter change the intensity of the effect of the filter, not the brightness
    /// </summary>
    public class MaskFilterBase : ParametricFilterKernelBase
    {
        public MaskFilterBase() : base()
        {
        }
        
        public override SpatialFilterKernel ApplyToSpatialFilter(SpatialFilterKernel InputFilter, SpatialFilterEngineState stateObject)
        {
 	        return InputFilter.AdjustEffectIntensity(1);
        }
    }

    public class LinearVignetteMask : MaskFilterBase
    {        
        public LinearVignetteMask()
            : base()
        {            
        }

        public override SpatialFilterKernel ApplyToSpatialFilter(SpatialFilterKernel InputFilter, SpatialFilterEngineState stateObject)
        {
            int relC = stateObject.CurrentColumn - (stateObject.Width / 2);
            int relR = stateObject.CurrentRow - (stateObject.Height / 2);

            float radius = (float)Math.Sqrt(Math.Pow(relC, 2) + Math.Pow(relR, 2));
            float maxradius = (float)Math.Sqrt(Math.Pow(stateObject.Width / 2, 2) + Math.Pow(stateObject.Height / 2, 2));

            float f = (radius / maxradius);

            return InputFilter.AdjustEffectIntensity (f);
        }

    }

    public class PowVignetteMask : MaskFilterBase
    {
        float _intensity;
        public PowVignetteMask(float Intensity)
            : base()
        {
            _intensity = Intensity;
        }

        public override SpatialFilterKernel ApplyToSpatialFilter(SpatialFilterKernel InputFilter, SpatialFilterEngineState stateObject)
        {
            int relC = stateObject.CurrentColumn - (stateObject.Width / 2);
            int relR = stateObject.CurrentRow - (stateObject.Height / 2);

            float radius = (float)Math.Sqrt(Math.Pow(relC, 2) + Math.Pow(relR, 2));
            float maxradius = (float)Math.Sqrt(Math.Pow(stateObject.Width / 2, 2) + Math.Pow(stateObject.Height / 2, 2));
           
            float f = (float)(Math.Pow((radius / maxradius),_intensity));

            return InputFilter.AdjustEffectIntensity(f);

        }       
    }
}
